package com.viknix.threadpool.manager.autoconfigure;

import com.viknix.threadpool.manager.client.model.InstanceInfo;
import com.viknix.threadpool.manager.client.util.InstanceIdUtil;
import lombok.AllArgsConstructor;
import lombok.SneakyThrows;
import org.springframework.context.annotation.Bean;
import org.springframework.core.env.ConfigurableEnvironment;

import java.net.InetAddress;

/**
 * @Author: Dongqi
 * @Date: 2021/11/03 18:38
 * @Version 1.0
 * @Description:
 */
@AllArgsConstructor
public class TpmDiscoveryConfig {

    private ConfigurableEnvironment environment;

    @Bean
    @SneakyThrows
    public InstanceInfo instanceConfig() {

        InstanceInfo instanceInfo = new InstanceInfo();
        instanceInfo.setAppName(environment.getProperty("spring.application.name"));
        instanceInfo.setHostName(InetAddress.getLocalHost().getHostAddress());
        instanceInfo.setInstanceId(InstanceIdUtil.getDefaultInstanceId(environment));
        instanceInfo.setIpApplicationName(InstanceIdUtil.getIpApplicationName(environment));
        return instanceInfo;
    }
}
